package com.zglc.ms.shop.service;

import com.zglc.ms.shop.dao.PointDao;
import com.zglc.ms.shop.dao.PointRuleDao;
import com.zglc.ms.shop.model.PointRuleVo;
import com.zglc.ms.shop.model.UserPoint;
import com.zglc.ms.shop.model.UserPointRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class PointService {

    @Autowired
    PointDao pointDao;

    @Autowired
    PointRuleDao pointRuleDao;

    public List<UserPoint> getUserPoint(int userId) {
        return pointDao.getUserPoint(userId);
    }

    public List<UserPointRecord> getUserPointRecord(int userId, int type, int page, int pageNum) {
        List<UserPointRecord> list = pointDao.getUserPointRecord(userId, type, page, pageNum);
        return list;
    }

    public Integer getUserPointRecordCnt(int userId, int type) {
        return pointDao.getUserPointRecordCnt(userId, type);
    }

    public Map<Integer, String> getRuleMap() {
        List<PointRuleVo> rules = pointRuleDao.findAll();
        Map<Integer, String> ruleMap = rules.stream()
                .collect(Collectors.toMap(rule -> rule.getId(), rule -> rule.getRuleName()));
        ruleMap.put(0, "现金");
        return ruleMap;
    }

}